package com.yjd.pub.settlement.service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.settlement.model.ClearDayDetailModel;
import com.yjd.comm.settlement.service.IClearDayDetailService;
import com.yjd.comm.util.FrameUtil;
import com.yjd.pub.settlement.dao.IClearDayDetailDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <b>description</b>：日结算明细业务实现<br>
 * <b>time</b>：2017-08-11 17:27:54 <br>
 * <b>author</b>：  yangchangyan@yijiedai.com
 */
@Service("clearDayDetailService")
public class ClearDayDetailServiceImpl extends BaseServiceImpl implements IClearDayDetailService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public ClearDayDetailModel insert(ClearDayDetailModel model) throws Exception {
		return this.clearDayDetailDao.insertModel(model, true);
	}

	@Override
	public int insertBatch(List<ClearDayDetailModel> models) throws Exception {
		this.clearDayDetailDao.insertBatch(models, true);
		return models.size();
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(ClearDayDetailModel model) throws Exception {
		return this.clearDayDetailDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(long id) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id", id);
		return this.clearDayDetailDao.deleteModel(paramMap, true);
	}

	/**
	 * 统计日结 平台支出金额
	 *
	 * @param clear_date
	 * @return
	 * @throws Exception
	 */
	@Override
	public Double statisticsPfBorrowPriceOfDay(Integer clear_date) throws Exception {
		if(clear_date==null){
			FrameUtil.throwBaseException1("参数错误！");
		}
		return clearDayDetailDao.statisticsPfPrice(FrameUtil.newHashMap("field","clear_price","clear_date",clear_date,"flag",-1));
	}

	/**
	 * 统计日结 平台收入金额
	 *
	 * @param clear_date
	 * @return
	 * @throws Exception
	 */
	@Override
	public Double statisticsPfLoanPriceOfDay(Integer clear_date) throws Exception {
		if(clear_date==null){
			FrameUtil.throwBaseException1("参数错误！");
		}
		return clearDayDetailDao.statisticsPfPrice(FrameUtil.newHashMap("field","clear_price","clear_date",clear_date,"flag",1));
	}

	/**
	 * 统计日结 平台交易金额
	 *
	 * @param clear_date
	 * @return
	 * @throws Exception
	 */
	@Override
	public Double statisticsPfTradePriceOfDay(Integer clear_date) throws Exception {
		if(clear_date==null){
			FrameUtil.throwBaseException1("参数错误！");
		}
		return clearDayDetailDao.statisticsPfPrice(FrameUtil.newHashMap("field","order_price","clear_date",clear_date,"flag",-1));
	}

	/**
	 * 统计日结 平台交易笔数
	 *
	 * @param clear_date
	 * @return
	 * @throws Exception
	 */
	@Override
	public int statisticsPfTradeCountOfDay(Integer clear_date) throws Exception {
		if(clear_date==null){
			FrameUtil.throwBaseException1("参数错误！");
		}
		return clearDayDetailDao.statisticsPfNum(FrameUtil.newHashMap("clear_date",clear_date,"flag",-1));
	}

	/**
	 * 统计日结 平台退回笔数
	 *
	 * @param clear_date
	 * @return
	 * @throws Exception
	 */
	@Override
	public int statisticsPfRefundCountOfDay(Integer clear_date) throws Exception {
		if(clear_date==null){
			FrameUtil.throwBaseException1("参数错误！");
		}
		return clearDayDetailDao.statisticsPfNum(FrameUtil.newHashMap("clear_date",clear_date,"flag",1));
	}

	@Override
	public List querySettlementDetail(Map paramMap, DbWREnums write) throws Exception {
		return this.clearDayDetailDao.querySettlementDetail(paramMap, write.isWrite());
	}

	@Resource
	private IClearDayDetailDao clearDayDetailDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.clearDayDetailDao;
	}

}
